<?php
/*
# TCE - Tight Control Environment: Hosting Platform
# Copyright (c) 2006 by the TightControl Dev Team
# http://tce.mystichost.net
#
#
# License:
#    This program is free software; you can redistribute it and/or
#    modify it under the terms of the MPL Mozilla Public License
#    as published by the Free Software Foundation; either version 1.1
#    of the License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    MPL Mozilla Public License for more details.
#
#    You may have received a copy of the MPL Mozilla Public License
#    along with this program.
#
#    An on-line copy of the MPL Mozilla Public License can be found
#    http://www.mozilla.org/MPL/MPL-1.1.html
#
#
# The TCE Home Page is at:
#
#    http://tce.mystichost.net
*/

/* Check if the master ftp controller has been loaded */
if (!class_exists('FTP_Controller')){
	throw new Exception('The FTP_Controller abstraction layer has not been found!');
}

/**
 * Controller frontend to a ProFTPd with MySQL support build in
 *
 */
class ProFTPD_MySQL_Controller extends FTP_Controller {
	private $Configuration = false; // Or replace with default :)

	/**
     * Creates a new FTP user with the given $Homedir
     *
     * @param string $Username
     * @param string $Password
     * @param string $Homedir
     * @param integer $UID
     * @param integer $GID
     * @param boolean $Enabled
     */
	function createUser($Username, $Password, $Homedir, $UID = 0, $GID = 0, $Enabled = true){

	}
	/**
     * Delete the given user
     *
     * @param string $Username
     * @param boolean $KeepFiles
     * @return boolean
     */
	function deleteUser($Username, $KeepFiles = true){

	}
	/**
	 * Disable the given user
	 *
	 * @param string $Username
    * @return boolean
	 */
	function disableUser($Username){

	}
	/**
	 * Enable the given user
	 *
	 * @param string $Username
    * @return boolean
	 */
	function enableUser($Username){

	}
	/**
     * Return a list of FTP users
     *
     * @param integer $From
     * @param integer $Limit
     * @return boolean
     */
	function listUsers($From = 0, $Limit = 0){

	}
	/**
     * Sets the hd quota of a certain user
     * When $SoftLimit is > $HardLimit then $HardLimit will be set equal with $HardLimit
     * 
     * @param string $Username
     * @param integer $SoftLimit
     * @param integer $HardLimit
     * @return boolean
     */
	function setQuota($Username, $SoftLimit = 0, $HardLimit = 0){

	}
	/**
     * Gets the soft limit for a FTP user
     *
     * @param string $Username
     * @return integer
     */
	function getSoftLimit($Username){

	}
	/**
     * Gets the hard limit for a FTP user
     *
     * @param string $Username
     * @return integer
     */
	function getHardLimit($Username){

	}
	/**
     * Returns information about the ftp server
     * Every class should return array('Version' => 'unknown', 'Online' => 'unknown', 'Product' => 'ProFTPd')
     * 
     * @return array
     */
	function getServerStatus(){

	}
	/**
	 * Returns a list of connections
	 *
	 * @param string $Username if not empty, only the connections for this user will be returned
	 * @return array of array ('id' => '', 'command' => '', 'time' => 0)
	 */
	function listConnections($Username = ''){

	}
	/**
	 * Kills a FTP session by its connection_id (returned from listConnections)
	 *
	 * @param integer $ConnectionID
	 * @param string $Username if this empty no checking on the owner of the process will be done
	 * @return boolean
	 */
	function killConnection($ConnectionID, $Username = ''){

	}
	/**
	 * Kills all connections
	 * 
	 * @param string $Username if this is not empty, only the ftp connections for the given user will be killed
	 *
	 */
	function killAllConnections($Username = ''){

	}
	/**
	 * Return true if the controller can list current ftp connections
	 *
	 * @return boolean
	 */
	function canListConnections(){

	}
	/**
	 * Return true if the controller can kill a ftp connections
	 *
	 * @return boolean
	 */
	function canKillConnections(){

	}
	/**
	 * Return true if the controller can handle quotas
	 *
	 * @return boolean
	 */
	function canHandleQuota(){

	}
	/**
	 * Return true if the controller can disable/enable ftp accounts
	 *
	 * @return boolean
	 */
	function canDisable(){

	}
	/**
	 * Returns an array of the information that is needed to handle the ftp server (db_name and so on)
	 * 
	 * Example result:
	 * 
	 * $Array[0] = array('Field' => 'SERVER', 'Name' => 'Server', 'Description' => 'The FTP server to connect to', 'Required' => false, 'Default' => '')
	 * @return array
	 */
	function getConfigFields(){
		$ConfigArr = array();
		$ConfigArr[] = array('Field' => 'MYSQL_SERVER','Name' =>  'MySQL Server', 'Description' => 'The address to the MySQL server where the ProFTPD tables are stored one', 'Required' => true);
		$ConfigArr[] = array('Field'=> 'MYSQL_USERNAME' ,'Name' => 'MySQL Username', 'Description' => 'The username to access the ProFTPD database', 'Required' => true);
		$ConfigArr[] = array('Field'=> 'MYSQL_PASSWORD' ,'Name' => 'MySQL Password', 'Description' => 'The password to access the ProFTPD database', 'Required' => true);
		$ConfigArr[] = array('Field'=> 'MYSQL_DATABASE' ,'Name' => 'MySQL Database', 'Description' => 'The ProFTPD database', 'Required' => true, 'Default' => 'proftpd');
		return $ConfigArr;
	}
	/**
	 * Sets the configuration
	 * 
	 * To know what kind of configuration options there are, check getConfigFields()
	 *
	 * @param array $Configuration
	 * @return boolean
	 */
	function setConfigFields($Configuration = false){
		$this->Configuration = $Configuration;
		// TODO Validate $Configuration and be sure that the required fields are set, otherwise return false or throw exception (sinnerg, 13/10/2006)
	}
	/**
	 * Ask to start interfacing with the FTP server using the configuration 
	 * set by setConfigFields  OR by supplying $Configuration
	 *
	 * @param variable $Configuration
	 * @return boolean
	 */
	function startInterface($Configuration = false){
		if ($Configuration){
			$this->setConfigFields($Configuration);
		}
	}
	/**
	 * Stop interfacing with the FTP server
	 * 
	 * Should be called in a __destruct() function 
	 * 
	 * @return boolean
	 */
	function endInterface(){
		return true;
	}
	/**
	 * Should return an array like this return array('Name' => 'FTP Controller', 'Description' => 'A FTP Controller');
	 *
	 * @return array
	 */
	function getControllerInfo(){
		return array('Name' => 'proftpd-mysql support', 'Description' => 'Support for ProFTPD servers store their users in a mysql database');
	}
}
/* Register it to the FTP_Controller */
FTP_Controller::Register('ProFTPD_MySQL_Controller');

?>